package dominia.net;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

public class Server {
	/** The default port on which MTG servers listen */
	static public int MTG_SERVER_PORT = 6751;


	private InetAddress srv_addr;
	private int         srv_port;

	/**
	 * The following fields are not setttable locally.  They are filled when an
	 * initial discovery connection is performed to a server.
	 */
	private String      srv_desc;
	private int         srv_total_slots;	/* total player slots */
	private int         srv_empty_slots;	/* empty player slots */

	public Server()
	{
		this.srv_desc = new String("No description");
		this.srv_port = MTG_SERVER_PORT;
	}

	public Server(InetAddress addr)
	{
		this();
		this.srv_addr = addr;
	}

	public Server(InetAddress addr, int port)
	{
		this(addr);
		
		this.srv_port = port;
	}

	public String getDesc()
	{
		return this.srv_desc;
	}
	
	public InetAddress getAddr()
	{
		return this.srv_addr;
	}

	public void setAddr(InetAddress addr)
	{
		this.srv_addr = addr;
	}

	public int getPort()
	{
		return this.srv_port;
	}

	public void setPort(int port)
	{
		this.srv_port = port;
	}

	public Socket connectTo()
	  throws IOException
	{
		Socket sock;
		
		sock = new Socket(this.srv_addr, this.srv_port);
		
		return sock;
	}
}
